<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>web2py.gluon.sneaky</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="web2py.gluon-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://www.web2py.com">web2py Web Framework</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        Package&nbsp;web2py ::
        <a href="web2py.gluon-module.html">Package&nbsp;gluon</a> ::
        Module&nbsp;sneaky
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="web2py.gluon.sneaky-module.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module sneaky</h1><span class="codelink"><a href="web2py.gluon.sneaky-pysrc.html">source&nbsp;code</a></span><br /><br />
<pre class="literalblock">

Experimetal multi-threaded web server created by Massimo Di Pierro
For lack of a better we'll call it Sneaky.
License: GPL2

This code would have not been possible without CherryPy wsgiserver,
a great example of Python web server.

- This code implements WSGI
- This code is API compatible with cherrypy
- It consists of less than 260 lines of code
- It is multi-threaded
- The number of threads changes dynamically between a min and a max
- Can handle chunking (request and response) [to be tested]
- supports SSL via the Cherrypy ssl adaptors

You can find an example of usage at the bottom of this file.

here are some tests and comparisons performed by Garrett Smith

RPS = requests per second
Time = average time in milliseconds to server each request
Benchmark = `ab -t 10 -c &lt;number of concurrent requests&gt;-r http://localhost`

100 Concurrent Requests
-----------------------
===============
App Server         RPS
==============
Fapws             7174
Landshark         4479
PHP-5             4191
modwsgi           3651
Tomcat 6          3554
Tornado           2641
Sneaky WSGI(*)    2372
CherryPy WSGI     2102
Phusion           1873
Jetty 6            937
Django WSGI        785
WEBrick             43
===============

1,000 Concurrent Requests
-------------------------
===============
App Server         RPS
===============
Fapws             5359
Landshark         4477
modwsgi           3449
PHP 5             3062
Tomcat 6          3014
Tornado           2452
Sneaky WSGI(*)    2415
CherryPy WSGI     2126
Phusion           1585
Jetty 6           1095
Django WSGI        953
WEBrick             50
===============

10,000 Concurrent Requests
--------------------------
===============
App Server         RPS
===============
Fapws             5213
Landshark         4239
Tomcat 6          2369
Tornado           2265
PHP 5             2239
Sneaky WSGI (*)   2225
modwsgi           2115
CherryPy WSGI     1731
Phusion           1247
Jetty 6            794
Django WSGI        890
WEBrick             84
===============

20,000 Concurrent Requests
--------------------------
===============
App Server         RPS
===============
Fapws             4788
Landshark         2936
Tornado           2153
Sneaky WSGI(*)    2130
PHP 5             1728
modwsgi           1374
Tomcat 6          1362
CherryPy WSGI     1294
Phusion            961
Django WSGI        790
Jetty 6            616
WEBrick             63
===============

</pre><br /><br />

<!-- ==================== CLASSES ==================== -->
<a name="section-Classes"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Classes</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Classes"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.sneaky.ChunkedReader-class.html" class="summary-name">ChunkedReader</a><br />
      class used to read chunked input
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.sneaky.Worker-class.html" class="summary-name">Worker</a><br />
      class representing a worker node
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.sneaky.Sneaky-class.html" class="summary-name">Sneaky</a><br />
      the actual web server
    </td>
  </tr>
</table>
<!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Functions</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Functions"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="formatdateRFC822"></a><span class="summary-sig-name">formatdateRFC822</span>()</span></td>
          <td align="right" valign="top">
            <span class="codelink"><a href="web2py.gluon.sneaky-pysrc.html#formatdateRFC822">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="errors_numbers"></a><span class="summary-sig-name">errors_numbers</span>(<span class="summary-sig-arg">errnames</span>)</span><br />
      utility to build a list of socket errors</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="web2py.gluon.sneaky-pysrc.html#errors_numbers">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a name="test_wsgi_app"></a><span class="summary-sig-name">test_wsgi_app</span>(<span class="summary-sig-arg">environ</span>,
        <span class="summary-sig-arg">start_response</span>)</span><br />
      just a test app</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="web2py.gluon.sneaky-pysrc.html#test_wsgi_app">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Variables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.sneaky-module.html#regex_head" class="summary-name">regex_head</a> = <code title="re.compile(r'^((http|https|HTTP|HTTPS)://[^/]+)?(?P&lt;method&gt;\w+)\s+(?P&lt;\
uri&gt;\S+)\s+(?P&lt;protocol&gt;\S+)')">re.compile(r'^<code class="re-group">(</code><code class="re-group">(</code>http<code class="re-op">|</code>https<code class="re-op">|</code>HTTP<code class="re-op">|</code>HTTPS<code class="re-group">)</code>://<code class="re-group">[^</code>/<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">)</code><code class="re-op">?</code><code class="re-group">(</code><code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.sneaky-module.html#regex_header" class="summary-name">regex_header</a> = <code title="re.compile(r'^\s*(?P&lt;key&gt;.*?)\s*:\s*(?P&lt;value&gt;.*?)\s*$')">re.compile(r'^\s<code class="re-op">*</code><code class="re-group">(?P&lt;</code><code class="re-ref">key</code><code class="re-group">&gt;</code>.<code class="re-op">*?</code><code class="re-group">)</code>\s<code class="re-op">*</code>:\s<code class="re-op">*</code><code class="re-group">(?P&lt;</code><code class="re-ref">value</code><code class="re-group">&gt;</code>.<code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="regex_chunk"></a><span class="summary-name">regex_chunk</span> = <code title="re.compile(r'^(?P&lt;size&gt;\w+)')">re.compile(r'^<code class="re-group">(?P&lt;</code><code class="re-ref">size</code><code class="re-group">&gt;</code>\w<code class="re-op">+</code><code class="re-group">)</code>')</code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="BUF_SIZE"></a><span class="summary-name">BUF_SIZE</span> = <code title="10000">10000</code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="SERVER_NAME"></a><span class="summary-name">SERVER_NAME</span> = <code title="'Sneaky'"><code class="variable-quote">'</code><code class="variable-string">Sneaky</code><code class="variable-quote">'</code></code>
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a href="web2py.gluon.sneaky-module.html#socket_errors_to_ignore" class="summary-name">socket_errors_to_ignore</a> = <code title="set([9, 32, 88, 102, 103, 104, 110, 111, 112, 113])"><code class="variable-group">set([</code>9<code class="variable-op">, </code>32<code class="variable-op">, </code>88<code class="variable-op">, </code>102<code class="variable-op">, </code>103<code class="variable-op">, </code>104<code class="variable-op">, </code>110<code class="variable-op">, </code><code class="variable-ellipsis">...</code></code>
    </td>
  </tr>
</table>
<!-- ==================== VARIABLES DETAILS ==================== -->
<a name="section-VariablesDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Variables Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-VariablesDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="regex_head"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">regex_head</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
re.compile(r'^<code class="re-group">(</code><code class="re-group">(</code>http<code class="re-op">|</code>https<code class="re-op">|</code>HTTP<code class="re-op">|</code>HTTPS<code class="re-group">)</code>://<code class="re-group">[^</code>/<code class="re-group">]</code><code class="re-op">+</code><code class="re-group">)</code><code class="re-op">?</code><code class="re-group">(?P&lt;</code><code class="re-ref">method</code><code class="re-group">&gt;</code>\w<code class="re-op">+</code><code class="re-group">)</code>\s<code class="re-op">+</code><code class="re-group">(?P&lt;</code><code class="re-ref"></code><span class="variable-linewrap"><img src="crarr.png" alt="\" /></span>
<code class="re-ref">uri</code><code class="re-group">&gt;</code>\S<code class="re-op">+</code><code class="re-group">)</code>\s<code class="re-op">+</code><code class="re-group">(?P&lt;</code><code class="re-ref">protocol</code><code class="re-group">&gt;</code>\S<code class="re-op">+</code><code class="re-group">)</code>')
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<a name="regex_header"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">regex_header</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
re.compile(r'^\s<code class="re-op">*</code><code class="re-group">(?P&lt;</code><code class="re-ref">key</code><code class="re-group">&gt;</code>.<code class="re-op">*?</code><code class="re-group">)</code>\s<code class="re-op">*</code>:\s<code class="re-op">*</code><code class="re-group">(?P&lt;</code><code class="re-ref">value</code><code class="re-group">&gt;</code>.<code class="re-op">*?</code><code class="re-group">)</code>\s<code class="re-op">*</code>$')
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<a name="socket_errors_to_ignore"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <h3 class="epydoc">socket_errors_to_ignore</h3>
  
  <dl class="fields">
  </dl>
  <dl class="fields">
    <dt>Value:</dt>
      <dd><table><tr><td><pre class="variable">
<code class="variable-group">set([</code>9<code class="variable-op">, </code>32<code class="variable-op">, </code>88<code class="variable-op">, </code>102<code class="variable-op">, </code>103<code class="variable-op">, </code>104<code class="variable-op">, </code>110<code class="variable-op">, </code>111<code class="variable-op">, </code>112<code class="variable-op">, </code>113<code class="variable-group">])</code>
</pre></td></tr></table>
</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="web2py.gluon-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://www.web2py.com">web2py Web Framework</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0beta1 on Fri Feb 26 06:00:53 2010
    </td>
    <td align="right" class="footer">
      <a href="http://epydoc.sourceforge.net">http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie()
  // -->
</script>
  
</body>
</html>
